﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using CanDichVu.Db;
using CanDichVu.Service.Vervices;

namespace CanDichVu.FrameWork.Conrtron
{
    public class UTContextKey
    {
        public static readonly string SessionContextKey = "Session_CanDichVu";
        private readonly UserSer _uSer = new UserSer();

        private ThanhVien users = null;
        public ThanhVien User
        {
            get
            {
                if (!HttpContext.Current.Request.IsAuthenticated)
                {
                    return null;
                }

                if (users == null)
                {
                    string userName = HttpContext.Current.User.Identity.Name;
                    if (!string.IsNullOrEmpty(userName) && users == null)
                    {
                        users = _uSer.GetByUserName(userName);
                    }
                }
                return users;
            }
            private set { users = value; }
        }

        public void LogOut()
        {
            User = null;
        }

    }
}
